package com.guoheng.safe.sys.service.impl;

import com.guoheng.safe.common.base.Result;
import com.guoheng.safe.sys.dto.UserLoginDTO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.guoheng.safe.sys.model.User;
import com.guoheng.safe.sys.mapper.user.UserMapper;
import com.guoheng.safe.sys.service.UserService;

import static com.guoheng.safe.common.enums.ErrorCodeEnum.SYS_ERR_USER_NON_EXISTENT;
import static com.guoheng.safe.common.enums.ErrorCodeEnum.SYS_ERR_USER_PASSWORD_ERROR;

/**
 * 类功能描述:　UserServiceImpl
 *
 * @author Eternal
 * @date 2019-32-15 11:32
 */
@Service
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;

    @Override
    public Result login(UserLoginDTO loginDTO) {
        User user = userMapper.login(loginDTO.getUserAccount());
        if (null == user){
            return Result.failure(SYS_ERR_USER_NON_EXISTENT);
        }
        if (!user.getPassword().equals(loginDTO.getPassword())){
            return Result.failure(SYS_ERR_USER_PASSWORD_ERROR);
        }
        return Result.success();
    }
}
